import client from '../bot'

export interface Next {
    (): void
}

class App {
    /**
     * 监听事件
     * @param eventName 事件名
     * @param callbacks 回调函数数组
     */
    public on<T>(eventName: string, ...callbacks: ((ctx: T, next: Next) => void)[]) {
        client.on(eventName, (event) => {
            let index = 0
            const next = () => {
                if (index >= callbacks.length) return
                const callback = callbacks[index++]
                if (callback) {
                    callback(event, next)
                }
            }

            if (!callbacks.length) return
            callbacks[index++](event, next)
        })
    }
}

export default new App()
